package com.example.demo1.common;

import lombok.Data;

@Data
public class AppResult<T> {
    private int code;
    private String message;
    private T data;

    public static <T> AppResult<T> success(T data) {
        AppResult<T> result = new AppResult<>();
        result.setCode(200);
        result.setMessage("success");
        result.setData(data);
        return result;
    }

    public static <T> AppResult<T> error(int code, String message) {
        AppResult<T> result = new AppResult<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
    public static <T> AppResult<T> error(ResultCode resultCode) {
        AppResult<T> result = new AppResult<>();
        result.setCode(resultCode.getCode());
        result.setMessage(resultCode.getMessage());
        return result;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
